package org.example;

import java.util.HashMap;
import java.util.Map;

public class Test1 {
    //leetcode 单词规律
    //https://leetcode.cn/problems/word-pattern/description/?envType=study-plan-v2&envId=top-interview-150
    public boolean wordPattern(String pattern, String s) {
        Map<Character,String> hash = new HashMap<>();
        String[] ss = s.split(" ");
        int n1 = pattern.length(), n2 = ss.length;
        if (n1 != n2) return false;
        for (int i = 0; i < n1; i++) {
            char key = pattern.charAt(i);
            String value = hash.get(key);
            if (value == null) {
                if (hash.values().contains(ss[i])) return false;
                hash.put(key,ss[i]);
            }else {
                if (!value.equals(ss[i])) return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String s = "abcd cd";
        String[] ss = s.split(" ");
        for (String c : ss) {
            System.out.println(c);
        }
        Map<Character,String> hash = new HashMap<>();
    }
}
